package com.situ.springboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.springboot.mapper.TypeMapper;
import com.situ.springboot.pojo.Type;
import com.situ.springboot.pojo.query.TypeQuery;
import com.situ.springboot.service.ITypeService;
import com.situ.springboot.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TypeServiceImpl implements ITypeService {

    @Autowired
    private TypeMapper typeMapper;

    @Override
    public List<Type> selectAll() {
        return typeMapper.selectAll();
    }

    @Override
    public PageResult<Type> selectByPage(TypeQuery typeQuery) {
        PageHelper.startPage(typeQuery.getPage(), typeQuery.getLimit());
        List<Type> list = typeMapper.selectByPage(typeQuery);
        PageInfo<Type> pageInfo = new PageInfo<>(list);
        int totalCount = (int) pageInfo.getTotal();
        return new PageResult<>(0, "", totalCount, list);
    }
}
